package com.sos.ui
{ 
	import com.greensock.data.TweenMaxVars;
	import com.greensock.easing.*;
	import com.greensock.TimelineMax;
	import com.greensock.TweenMax;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.geom.Point;
     
    public class Ball extends MovieClip 
    { 
		private var _baseX:int;
		private var _baseY:int = -40;
		
		public function Ball() {
			y = _baseY;
			TweenMax.to(this, 1, new TweenMaxVars().rotation(360).ease(Linear.easeNone).repeat(-1));
			
        } 
		
		public function animatePassTo(targetPoint:Point, revert:Boolean = true):TimelineMax {
			_baseX = this.x;
			var tl:TimelineMax = new TimelineMax(new TweenMaxVars().onCompleteListener(resetPosition));
			tl.insert(new TweenMax(this, 1.5, new TweenMaxVars().bezier([ { x:this.x, y:targetPoint.y }, { x:targetPoint.x, y:targetPoint.y } ]).ease(Linear.easeNone)));
			tl.append(new TweenMax(this, 0.5, new TweenMaxVars().autoAlpha(0)));
			
			tl.play();
			
			return tl;
			
		}
		
		public function resetPosition(e:Event):void {
			x = _baseX;
			y = _baseY;
			visible = true;
			alpha = 1;
		}
    } 
}